VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsClientes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Dim vSQL As String

Public pNumError As Long
Public pDesError As String
Public pCanReg As Long
Public pRS As ADODB.Recordset
Public pIdDevuelto As Long

Private vIdCliente As Long

Public Property Let IdCliente(ByVal VData As Long)
    vIdCliente = VData
End Property
Public Property Get IdCliente() As Long
    IdCliente = vIdCliente
End Property

Private Sub AsignarValores(Optional ByVal rs As ADODB.Recordset, Optional pNoAsigRs As Boolean)
    If Not pNoAsigRs Then
        Set Me.pRS = rs
    End If
    Me.pCanReg = objCnxAeros.pCanReg
    Me.pDesError = objCnxAeros.pDesError
    Me.pIdDevuelto = objCnxAeros.pUltIdenOtor
    Me.pNumError = objCnxAeros.pNumError
End Sub

Public Function sel_Localidades()
Dim rs As New ADODB.Recordset
Dim strSQL As String
    strSQL = "SELECT id_Localidad, localidad From localidades"
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Function

Public Function sel_Clientes(Optional ByVal nombreCliente)
Dim rs As New ADODB.Recordset
Dim strSQL As String

    If Not IsMissing(nombreCliente) Then
        strSQL = "SELECT id_cliente,cliente From clientes WHERE fecha_baja is null AND Cliente like '%" & nombreCliente & "%' ORDER BY cliente"
    Else
        strSQL = "SELECT id_cliente,cliente From clientes WHERE fecha_baja is null ORDER BY cliente"
    End If
    
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Function


Public Function reporte_Clientes()
Dim rs As New ADODB.Recordset
Dim strSQL As String

strSQL = "SELECT c.id_cliente, " + Chr(10) _
    + "       c.cliente, " + Chr(10) _
    + "       c.direccion, " + Chr(10) _
    + "       l.localidad, " + Chr(10) _
    + "       c.fecha_nac, " + Chr(10) _
    + "       c.telefono, " + Chr(10) _
    + "       c.celular, " + Chr(10) _
    + "       c.mail " + Chr(10) _
    + "FROM   clientes c " + Chr(10) _
    + "       INNER JOIN localidades l " + Chr(10) _
    + "            ON  l.id_localidad = c.id_localidad"
    
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Function

Public Function reporte_CumplesClientes(ByVal pDesde As Date, ByVal pHasta As Date)
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim vDesde As Long
Dim vHasta As Long

    vDesde = 10000 + (Month(pDesde) * 100) + Day(pDesde)
    vHasta = 10000 + (Month(pHasta) * 100) + Day(pHasta)
    strSQL = "SELECT c.id_cliente, c.cliente, c.direccion, l.localidad, c.fecha_nac, " & _
                    "c.telefono, c.celular, c.mail " & _
                "FROM clientes c " & _
                "INNER JOIN localidades l ON  l.id_localidad = c.id_localidad " & _
                "WHERE c.fecha_baja IS NULL AND (10000 + (month(fecha_nac) * 100) + day(fecha_nac)) >= " & vDesde & _
                " AND (10000 + (month(fecha_nac) * 100) + day(fecha_nac)) <= " & vHasta
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Function

Public Function ActualizarCliente_by_ID(ByVal id_cliente As Long, ByVal cliente As String, _
                                    ByVal fechaNac As Date, ByVal telefono As String, ByVal direccion As String, _
                                    ByVal mail As String, ByVal web As String, ByVal celular As String, ByVal id_localidad As Long) As Boolean
Dim strSQL As String

   'Atualizar proveedor by ID
    strSQL = " UPDATE clientes SET cliente='" & cliente & _
                                        "',fecha_nac='" & fechaNac & _
                                        "',telefono='" & telefono & _
                                        "',direccion='" & direccion & _
                                        "',mail='" & mail & _
                                        "',web='" & web & _
                                        "',celular='" & celular & _
                                        "',id_localidad =" & id_localidad & _
                                        " WHERE clientes.id_cliente =" & id_cliente
                                        
    If objCnxAeros.EjecutarComando(strSQL) Then
        ActualizarCliente_by_ID = True
    Else
        ActualizarCliente_by_ID = False
    End If

End Function

Public Function BorrarCliente_by_ID(ByVal id As Long)
Dim strSQL As String

    'Atualizar proveedor by ID
    strSQL = " UPDATE clientes SET fecha_baja ='" & Date & "'" & _
             " WHERE clientes.id_cliente =" & id

    If objCnxAeros.EjecutarComando(strSQL) Then
        BorrarCliente_by_ID = True
    Else
        BorrarCliente_by_ID = False
    End If

End Function

Public Function grabarCliente(ByVal cliente As String, _
                               ByVal fechaNac As Date, _
                               ByVal telefono As String, _
                               ByVal direccion As String, _
                               ByVal mail As String, _
                               ByVal web As String, _
                               ByVal celular As String, _
                               ByVal id_localidad As Long)
Dim strSQL As String

       
    
    'agregar nuevo cliente
    
    strSQL = " INSERT INTO clientes (cliente,fecha_nac,telefono,direccion,mail,web,celular,id_localidad) values (" & _
                                        "'" & cliente & _
                                        "','" & fechaNac & _
                                        "','" & telefono & _
                                        "','" & direccion & _
                                        "','" & mail & _
                                        "','" & web & _
                                        "','" & celular & _
                                        "'," & id_localidad & ")"
                                     
                                        
    If objCnxAeros.EjecutarComando(strSQL) Then
        grabarCliente = True
    Else
        grabarCliente = False
    End If
    AsignarValores , True

End Function

Public Function cargarCliente_by_ID(ByVal id As Long)
Dim rs As New ADODB.Recordset
Dim strSQL As String

   'Cargar Cliente by ID
   strSQL = " SELECT c.id_cliente, c.cliente,c.fecha_nac, c.telefono, c.direccion, c.mail, c.web, " & _
            " c.celular, c.id_localidad, c.notas, " & _
            " c.fecha_baja, c.motivo_baja" & _
            " FROM clientes c, localidades loc" & _
            " WHERE c.id_localidad = loc.id_localidad " & _
            " AND c.id_cliente = " & id
    
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    
    AsignarValores rs

End Function




